<template>
  <el-container id="root" v-if="ifShow">
    <el-header>
      <span class="title">计算机协会</span>
      <span class="title" style="position: absolute;left: 40%">{{msg}}</span>
      <el-button @click="quit" type="warning" style="position: absolute;top:20%;right:5%">退出登录</el-button>
    </el-header>
    <el-container id="main">
      <el-aside>
        <el-menu
        default-active="/Home/study"
        class="el-menu-vertical-demo"
        height='90%'
        router
        >
          <el-menu-item index="/Home/study">
            <template slot="title">
              <i class="el-icon-s-order"></i>
              <span>学习打卡</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/Home/manage">
            <i class="el-icon-s-home"></i>
            <span slot="title">群组管理</span>
          </el-menu-item>
<!--          <el-submenu index="2">-->
<!--            <template slot="title">-->
<!--              <i class="el-icon-location"></i>-->
<!--              <span>群组管理</span>-->
<!--            </template>-->
<!--            <el-menu-item-group>-->
<!--              <template slot="title">我管理的群</template>-->
<!--              <el-menu-item index="/manage">计协</el-menu-item>-->
<!--              <el-menu-item index="/manage">创数据</el-menu-item>-->
<!--            </el-menu-item-group>-->
<!--          </el-submenu>-->
        </el-menu>
      </el-aside>
      <el-main>
        <div class="baseMain">
          <!-- 打卡页面和群组管理页面在此显示 -->
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>



export default {
  name: 'Home',
  data(){
    return{
      ifShow:false,
      msg:''
    }
  },
  components: {
    
  },
  methods:{
    quit(){
      this.$confirm('确认退出登录','提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
          localStorage.removeItem('token')
          this.$router.push('/')
      })
    },
    getusername(){
      this.axios.post('/user/getNickname').then(res=>{
        var date = new Date()
        var hours = date.getHours()
        if(hours>=7&&hours<=11){
          this.msg=res.data+',上午好'
        }
        else if(hours>11&&hours<=15){
          this.msg=res.data+',中午好'
        }
        else if(hours>15&&hours<=19){
          this.msg=res.data+',下午好'
        }
        else if(hours>19&&hours<21){
          this.msg=res.data+',晚上好'
        }
        else{
          this.msg=res.data+',熬夜伤身体，睡睡更健康'
        }
        this.ifShow=true
      })
    },
  },
  mounted(){
    this.getusername()
  },
  //没token不让进，
  beforeRouteEnter(to,from,next){
    if(localStorage.token===undefined){
      next('/')
    }
    else{
      next()
    }
  }
}


</script>
<style>
  *{
    margin: 0;
    padding: 0;
  }
  html,body{
    height: 100%;
    width: 100%;
  }
  #root{
    height: 100%;
    width: 100%;
  }
  #main{
    height: 100%;
    width: 100%;
  }
  .el-aside{
    width: 15% !important;
    height: 100% !important;
    background-color: #f4f5f7;
  }
  .el-main{
    height:100%
  }
  .el-header{
    position: relative;
    height: 10% !important;
    background-color: #0093E9;
    background-image: linear-gradient(160deg, #0093E9 0%, #80D0C7 100%);

  }
  .el-menu-item{
    background-color: #f4f5f7;
  }
  .title{
    position: absolute;
    color: aliceblue;
    font-size: 40px;
    font-family: "STKaiti";
    top: 15px;
    left: 27px;
  }
  .baseMain{
    width: 100%;
    height: 100%;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  }
</style>